home *** CD-ROM | disk | FTP | other *** search
- /*
- File: InfoDlg.cpp
-
- Contains: implementation of the Info object including ShowPartFrameInfo
-
- Owned by: Ed Lai
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <23> 12/18/96 DH 1613491: Don't put up Alert twice.
- <22> 12/9/96 EL 1354755: need alert when part kind change
- in InfoDialog fails.
- <21> 12/3/96 JP 1401371,1162540: Call SetProcessName &
- SetProcessIcon
- <20> 10/10/96 RA 1343748: Pass around thePartSU so we can
- use a preferred editor string for NoPart.
- Rolled out 1353949 changes
- <19> 10/7/96 RA 1353949: Invalidate facets during editor
- swapping
- <18> 10/4/96 EL 1392459: if rebind fails, continue to
- display the info dialog.
- <17> 9/13/96 EL 1385235: Kind Menu should dispaly every
- stored kind as active.
- <16> 9/12/96 eeh 1386008: weak link against appleguidelib
- <15> 9/11/96 eeh 1386008: AG fix for 68K
- <14> 9/10/96 eeh 1386008: AppleGuide support (incomplete)
- <13> 9/6/96 TJ Fixed build break.
- <12> 9/4/96 EL 1306385: Remove user item that are used as
- default button in dialog. 1364013: button
- down on size change would continue if
- button stays down. 1343245: rebind if
- nopart but editor is now available.
- <11> 7/10/96 EL 1366381: Use dirty flags to avoid
- unnecessary rewrite of part name and
- comments.
- <10> 7/8/96 EL 1364853: Use ODSetPartNameReturnError so
- that no alert is needed if user cancel. Do
- not use ParamText to set the creation and
- modification date.
- <9> 7/8/96 eeh undo task 10008 (AppleGuide buttons)
- <8> 6/25/96 EL 1361737: If prefered kind not supported by
- current editor, add editor to editor list
- in menu.
- <7> 6/23/96 NP 10002: Launch time speedups.
- <6> 6/22/96 EL 1344140: dialogLib's ShowPartFrameInfo now
- returns ODError. 1299865: when editor list
- change from single to mulltiple, show popup
- again.
- <5> 6/21/96 jpa T10002: Changed default heap size.
- <4> 6/21/96 eeh task 10008: add buttons etc. for AppleGuide
- <3> 6/21/96 RA T10025: Call InitBndNSUtils
- <2> 6/19/96 EL 1321655: latest dialog design from the HI
- team. 1258753: Use static text instead of
- popup menu if there is only 1 editor in
- list.
- <0> 6/7/96 eeh first checked in (based on Info.cpp)
-
- In Progress:
-
- */
-
-
- #define VARIABLE_MACROS
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- #ifndef _AGSUPPORT_
- #include "AGSupprt.h"
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include <FrFaItr.xh>
- #endif
-
- #ifndef _INFODEFS_
- #include <InfoDefs.h>
- #endif
-
- #ifndef _PREFS_
- #include "Prefs.h"
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef SOM_ODSettingsExtension_xh
- #include <Settings.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StandardExtensions_defined
- #include <StdExts.xh>
- #endif
-
- #ifndef _PASCLSTR_
- #include <PasclStr.h>
- #endif
-
- #ifndef _ODMEMORY_
- #include <ODMemory.h>
- #endif
-
- #ifndef _PLFMFILE_
- #include <PlfmFile.h>
- #endif
-
- #ifndef SOM_ODTypeList_xh
- #include <TypeList.xh>
- #endif
-
- #ifndef SOM_ODTypeListIterator_xh
- #include <TypLsItr.xh>
- #endif
-
- #ifndef SOM_ODBinding_xh
- #include <ODBindng.xh>
- #endif
-
- #ifndef _BNDNSUTL_
- #include <BndNSUtl.h>
- #endif
-
- #ifndef _DLOGUTIL_
- #include <DlogUtil.h>
- #endif
-
- #ifndef _DOCUTILS_
- #include <DocUtils.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef _ITEXT_
- #include <IText.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _EDITRSET_
- #include <EditrSet.h>
- #endif
-
- #ifndef _ISOSTR_
- #include <ISOStr.h>
- #endif
-
- #ifndef _SHELLDEF_
- #include "ShellDef.h"
- #endif
-
- #ifdef __SC__
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
- #else
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
- #endif
-
- #ifndef __STRING__
- #include <String.h>
- #endif
-
- #ifndef __GESTALTEQU__
- #include <GestaltEqu.h>
- #endif
-
- #ifndef __APPLEGUIDE__
- #include <AppleGuide.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __TEXTEDIT__
- #include <TextEdit.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __CONTROLS__
- #include <Controls.h>
- #endif
-
- #ifndef SOM_ODPartWrapper_xh
- #include <PartWrap.xh>
- #endif
-
- #ifndef _INFOUTIL_
- #include <InfoUtil.h>
- #endif
-
- #ifndef _STDTYPIO_
- #include <StdTypIO.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef __PALETTES__
- #include <Palettes.h>
- #endif
-
- #ifndef __ICONS__
- #include <Icons.h>
- #endif
-
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif
-
- #ifndef _TRANSUTL_
- #include <TransUtl.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef SOM_ODStorageSystem_xh
- #include <ODStor.xh>
- #endif
-
- #ifndef SOM_ODNameSpaceManager_xh
- #include <NmSpcMg.xh>
- #endif
-
- #ifndef _PROCESSHACK_
- #include "ProcessHack.h"
- #endif
-
- #ifndef _ORDCOLL_
- #include "OrdColl.h"
- #endif
-
- #ifndef _BINDINGUTILS_
- #include "BindingUtils.h"
- #endif
-
- #pragma segment ODInfo
-
- //=========================================================================
- // Globals
- //=========================================================================
-
- static ODSession* gSession; // For use in Dialog Filter Proc
- static ODFrame* gFrame; // For use in Dialog Filter Proc
- static ODName* gKindName;
-
- // For use in Document Heap Dialog Filter Proc
- static ODHandle gArrowBtnsPictOff;
- static ODHandle gArrowBtnsPictTopOn;
- static ODHandle gArrowBtnsPictBotOn;
- static long gSizeDialogClickTime;
- static ODSShort gSizeDialogClickAt = 0;
-
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- const short kControlInactive = 255;
- const long kWaitTicksForMoreAction = 20;
-
- //==============================================================================
- // Scalar types
- //==============================================================================
-
- typedef char ODHandleState;
- struct DrawProcInfoStruct {
- ODIText* authorName;
- ODIText* category;
- };
- typedef struct DrawProcInfoStruct DrawProcInfoStruct, *DrawProcInfo;
-
- //==============================================================================
- // Function Prototypes
- //==============================================================================
-
- ODStatic void SetCategory( ODPart* part,
- Handle categoryItem,
- ODNameSpaceManager* nsm);
-
- ODStatic void GenerateEditorsList(ODSShort currentKindItem, ODTypeList* kindsList,
- EditorSet* editorList,
- ODNameSpaceManager* nsm);
-
- ODStatic void SetSizeText(DialogPtr dlg, ODSShort item, ODULong size);
-
- ODStatic void SetModifiedByText(DialogPtr dlg, ODSShort item, ODName* name);
-
- ODStatic ODBoolean GetDialogBoolean(DialogPtr dlg, short itemNo);
- ODStatic void SetDialogBoolean(DialogPtr dlg, short itemNo, ODBoolean bool, ODBoolean active);
- ODStatic void GetPStrFromDialog(DialogPtr dlg, short itemNo, Str255 pStr);
- ODStatic void SetDialogFromPStr(DialogPtr dlg, short itemNo, Str255 pStr, ODBoolean editable, ODBoolean selectIt);
- ODStatic void SetNumText(DialogPtr dlg, ODSShort item, ODSLong numValue);
-
- ODStatic void SetModCreatDateTimeText( Environment* ev, DialogPtr dlg, ODStorageUnit* partSU);
-
- ODStatic pascal void DrawThumbnail(DialogPtr theDialog, short theItem);
-
- ODStatic pascal void DrawIntlStaticText(DialogPtr dialog, SInt16 item);
-
- ODStatic void DeleteAllMenuItems(MenuHandle theMenu);
-
- ODStatic ODIText* PickOneIText( ODIText* itext1, ODIText* itext2 );
- ODStatic ODScriptCode GetRealScriptCode( ODIText* itext );
- ODStatic void EditorAsPopupOrStaticText( DialogPtr dialog, EditorSet* editorsList, MenuHandle editorMenu);
-
- ODStatic void ParamDlgText( DialogPtr dlg, short item, char* search1, Str255 str1,
- char* search2, Str255 str2 );
-
- //------------------------------------------------------------------------------
- // Document Heap Dialog Prototypes
- //------------------------------------------------------------------------------
-
- ODStatic void ShowSizeDialog(Environment* ev, ODSession* session,
- PlatformFile* file, Str255 partNameS255, ODBoolean allowEditing);
- ODStatic ODULong DHGetPreferredSizeInSIZE(PlatformFile* file, ODSShort resourceID);
- ODStatic void DHSetPreferredSizeInSIZE(PlatformFile* file, ODSShort resourceID,
- PlatformFile* fromFile, ODSShort fromResID, ODULong numKBytes);
-
- ODStatic ODULong DHGetODDefaultHeapSize();
- ODStatic void DHSetODDefaultHeapSize(PlatformFile* documentFile, ODULong numKBytes);
- ODStatic ODULong DHGetDocumentPreferredHeapSize(PlatformFile* file);
- ODStatic void DHClearDocumentPreferredHeapSize(PlatformFile* file);
- ODStatic void DHSetDocumentPreferredHeapSize(PlatformFile* file, ODULong numKBytes);
-
- //==============================================================================
- // NewKindPopup
- //==============================================================================
-
- static ODTypeList* NewKindPopup(Environment *ev,
- ODPartWrapper* part,
- ControlHandle popupHandle,
- MenuHandle kindMenu,
- ODSShort* currentKindItem,
- ODSShort* translateItem)
- {
- ODStorageUnit* partSU = part->GetStorageUnit(ev);
- ODSession* session = partSU->GetSession(ev);
- ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
-
- TempODType theKind = kODNULL;
-
- ODTypeList* kindList = session->GetStorageSystem(ev)->CreateTypeList(ev,(ODTypeList*)kODNULL);
-
- ContentValueTypes(partSU, kindList);
-
- ODSShort valueCount = kindList->Count(ev);
-
- TempODEditor editorID = part->GetEditor(ev);
- GetAllKindsForEditor(nsm, kindList, editorID);
- theKind = ODGetKindFromPartSU(ev, partSU); // OK for theKind to be null
- InitKindsPopup(kindList, theKind, popupHandle, valueCount, currentKindItem, kindMenu, translateItem, gSession, partSU);
-
- return kindList;
- }
-
-
- //==============================================================================
- // NewEditorPopup
- //==============================================================================
-
- static EditorSet* NewEditorPopup(Environment *ev,
- ODPartWrapper* part,
- ControlHandle popupHandle,
- MenuHandle editorMenu,
- ODTypeList* kindList,
- ODSShort currentKindItem,
- ODEditor editorID,
- ODSShort* currentEditorItem)
- {
- ODSession* session = part->GetStorageUnit(ev)->GetSession(ev);
- ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
-
- EditorSet* editorsList = new EditorSet;
- THROW_IF_NULL(editorsList);
- editorsList->InitEditorSet();
-
- TempODType initialKind = GetTypeListItem(kindList, currentKindItem);
- SetupEditorMenu(initialKind, editorsList, editorMenu, popupHandle, session, part->GetStorageUnit(ev));
- if ( !EditorSupportsKind(nsm, editorID, initialKind) ) {
- editorsList->AddEditor(editorID);
- SetupEditorMenu(initialKind, editorsList, editorMenu, popupHandle, session, part->GetStorageUnit(ev));
- }
- // determine which editor to check mark
- ODSShort item = 1;
- EditorSetIterator* editorIter = editorsList->CreateIterator();
- for (ODEditor editor = editorIter->First();
- editorIter->IsNotComplete();
- editor = editorIter->Next(), ++item)
- {
- if (ODISOStrEqual(editor, editorID)) {
- *currentEditorItem = item;
- break;
- }
- }
- ODDeleteObject( editorIter);
- SetControlValue(popupHandle, item);
-
- return editorsList;
- }
-
- //------------------------------------------------------------------------------
- // GetDialogBoolean
- //------------------------------------------------------------------------------
-
- ODStatic ODBoolean GetDialogBoolean(DialogPtr dlg, short itemNo)
- {
- short itemType;
- Handle itemHandle;
- Rect scratchRect;
-
- GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
- ASSERT_CONTROL_ITEM(itemType);
- return (ODBoolean)GetControlValue((ControlHandle)itemHandle);
- }
-
- //------------------------------------------------------------------------------
- // SetDialogBoolean
- //------------------------------------------------------------------------------
-
- ODStatic void SetDialogBoolean(DialogPtr dlg, short itemNo, ODBoolean bool, ODBoolean active)
- {
- short itemType;
- Handle itemHandle;
- Rect scratchRect;
-
- GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
- ASSERT_CONTROL_ITEM(itemType);
- SetControlValue((ControlHandle)itemHandle, bool);
- HiliteControl((ControlHandle)itemHandle, active ? 0:255);
- }
-
- //------------------------------------------------------------------------------
- // SetDialogItemAndUpdate
- //------------------------------------------------------------------------------
-
- ODStatic void SetDialogItemAndUpdate(DialogPtr dlg, short itemNo, Handle itemHandle)
- {
- short itemType;
- Handle dummy;
- Rect itemRect;
-
- GetDialogItem(dlg, itemNo, &itemType, &dummy, &itemRect);
- if (itemHandle)
- SetDialogItem(dlg, itemNo, itemType, itemHandle, &itemRect);
-
- RgnHandle itemRgn = ODNewRgn();
- if (itemRgn) {
- RectRgn(itemRgn,&itemRect);
- UpdateDialog(dlg, itemRgn);
- ODDisposeHandle((Handle)itemRgn);
- }
- }
-
- //------------------------------------------------------------------------------
- // GetDialogItemEnable
- //------------------------------------------------------------------------------
-
- ODStatic ODBoolean GetDialogItemEnable(DialogPtr dlg, short itemNo)
- {
- short itemType;
- Handle itemHandle;
- Rect itemRect;
-
- ODBoolean result = kODFalse;
-
- GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &itemRect);
- if ((itemDisable & itemType) == 0) { // item is enabled
- if (itemType & ctrlItem) { // if control make sure it is visible and active
- ControlPtr cPtr = (ControlPtr)(*itemHandle);
- if (cPtr->contrlVis == 255 && cPtr->contrlHilite == 0)
- result = kODTrue;
- }
- else
- result = kODTrue; // not control, then it is enabled
- }
- return result;
- }
-
- //------------------------------------------------------------------------------
- // GetPStrFromDialog
- //------------------------------------------------------------------------------
-
- ODStatic void GetPStrFromDialog(DialogPtr dlg, short itemNo, Str255 pStr)
- {
- short itemType;
- Handle itemHandle;
- Rect scratchRect;
-
- GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
- GetDialogItemText(itemHandle, pStr);
- }
-
- //------------------------------------------------------------------------------
- // SetDialogFromPStr
- //------------------------------------------------------------------------------
-
- ODStatic void SetDialogFromPStr(DialogPtr dlg, short itemNo, Str255 pStr, ODBoolean editable, ODBoolean selectIt)
- {
- short itemType;
- Handle itemHandle;
- Rect scratchRect;
-
- GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
- short newEditType = editable ? editText : statText;
- if ((itemType & (editText+statText)) != newEditType) { // dialog item type is not what we want
- SetDialogItem(dlg, itemNo, (itemDisable & itemType)+newEditType, itemHandle, &scratchRect);
- }
- SetDialogItemText(itemHandle, pStr);
- if (editable && selectIt)
- SelectDialogItemText(dlg, itemNo, 0, pStr[0]);
- }
-
- //------------------------------------------------------------------------------
- // GetITextFromDialog
- //------------------------------------------------------------------------------
-
- ODStatic ODIText* GetITextFromDialog(DialogPtr dlg, short itemNo, ODScriptCode script, ODLangCode lang)
- {
- short itemType;
- Handle itemHandle;
- Rect scratchRect;
-
- GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
- ODSize itemSize = GetHandleSize(itemHandle);
- return CreateIText( script, lang, (ODUByte*)*itemHandle, itemSize );
- }
-
- //------------------------------------------------------------------------------
- // SetDialogFromIText
- //------------------------------------------------------------------------------
-
- ODStatic void SetDialogFromIText(DialogPtr dlg, short itemNo, ODIText* iText, ODBoolean editable, ODBoolean selectIt)
- {
- short itemType;
- Handle itemHandle;
- Rect scratchRect;
- ODSize itemSize;
-
- GetDialogItem(dlg, itemNo, &itemType, &itemHandle, &scratchRect);
- short newEditType = editable ? editText : statText;
- if ((itemType & (editText+statText)) != newEditType) { // dialog item type is not what we want
- SetDialogItem(dlg, itemNo, (itemDisable & itemType)+newEditType, itemHandle, &scratchRect);
- }
- if (iText)
- itemSize = GetITextStringLength(iText);
- else
- itemSize = 0;
- SetHandleSize(itemHandle, itemSize);
- if (iText)
- ODBlockMove(GetITextPtr(iText), *itemHandle, itemSize);
- if (selectIt)
- SelectDialogItemText(dlg, itemNo, 0, itemSize);
- }
-
- ODStatic ODBoolean ITextStrEqual(ODIText *text1, ODIText *text2)
- {
- ODSize len1 = 0;
- if (text1)
- len1 = GetITextStringLength(text1);
- ODSize len2 = 0;
- if (text2)
- len2 = GetITextStringLength(text2);
- if (len1 != len2)
- return 0;
- else if (len1 == 0)
- return kODTrue;
- else
- return (ODISOStrNCompare(GetITextPtr(text1),GetITextPtr(text2),len1) == 0);
- }
-
- //------------------------------------------------------------------------------
- // GrayDialogItem
- //------------------------------------------------------------------------------
-
- ODStatic void GrayDialogItem(DialogPtr dlg, ODSShort item)
- {
- short itemType;
- Handle itemHandle;
- Rect itemRect;
- PenState savePen;
- WindowPtr savePort;
-
- PixPatHandle ppat = kODNULL;
- GetPort(&savePort);
- SetPort(dlg);
- GetDialogItem(dlg, item, &itemType, &itemHandle, &itemRect);
-
- GetPenState(&savePen);
-
- /* check if Color QuickDraw is available */
- long response;
- if( Gestalt(gestaltQuickdrawFeatures, &response)==noErr
- && BitTst(&response, 31-gestaltHasColor) ) {
- const RGBColor gray = {0x7FFF,0x7FFF,0x7FFF};
- ppat = NewPixPat();
- if( ppat )
- MakeRGBPat(ppat,&gray);
- }
-
- PenMode(patBic);
-
- if( ppat )
- PenPixPat(ppat);
- else
- PenPat(&ODQDGlobals.gray);
-
- PaintRect(&itemRect);
- ValidRect(&itemRect);
- SetPenState(&savePen);
-
- if( ppat )
- DisposePixPat(ppat);
- SetPort(savePort);
- }
-
- //------------------------------------------------------------------------------
- // SetNumText
- //------------------------------------------------------------------------------
-
- ODStatic void SetNumText(DialogPtr dlg, ODSShort item, ODSLong numValue)
- {
- short itemType;
- Handle itemHandle;
- Rect itemRect;
- Str255 text;
-
- NumToString(numValue, text);
- GetDialogItem(dlg, item, &itemType, &itemHandle, &itemRect);
- SetDialogItemText(itemHandle,text);
-
- }
-
- //------------------------------------------------------------------------------
- // GetOrderedCollectionElement
- //------------------------------------------------------------------------------
-
- ODStatic ODUShort GetOrderedCollectionElement(OrderedCollection* collection, ODUShort index)
- {
- OrderedCollectionIterator* oci = collection->CreateIterator();
- THROW_IF_NULL(oci);
-
- ODUShort elem = 0;
-
- for ( elem = (ODUShort) oci->First();
- oci->IsNotComplete();
- elem = (ODUShort) oci->Next() )
- {
- if ( --index == 0 )
- break;
- }
-
- ODDeleteObject(oci);
-
- return elem;
- }
-
- //------------------------------------------------------------------------------
- // ODGetFirstCategoryOfKind
- //------------------------------------------------------------------------------
- ODStatic ODType ODGetFirstCategoryOfKind(Environment* ev, ODType kind, ODNameSpaceManager* nsm)
- {
- ODTypeList* categoryList = GetCategoriesOfKind(nsm, kind);
- ODTypeListIterator* catIter = kODNULL;
- ODType category = kODNULL;
-
- if (categoryList)
- {
- catIter = categoryList->CreateTypeListIterator(ev);
- category = catIter->First(ev);
- ODDeleteObject(catIter);
- }
-
- return category;
- }
-
- //==============================================================================
- // ShowPartFrameInfo
- //==============================================================================
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- ODError ShowPartFrameInfo( Environment *ev, ODSession* session,
- ODFacet* facet, ODBoolean allowEditing);
-
- #ifdef __cplusplus
- }
- #endif
-
- //------------------------------------------------------------------------------
- // CallCheckScriptFirstThenStdFilterProc
- //------------------------------------------------------------------------------
-
- static pascal ODBoolean CallCheckScriptFirstThenStdFilterProc( DialogPtr dialog,
- EventRecord *event, short *itemHit)
- {
- if( event->what==updateEvt && (WindowPtr)event->message == dialog ) {
- BeginUpdate(dialog);
- UpdateDialog(dialog, dialog->visRgn);
- if (GetDialogItemEnable(dialog, kPartInfoShowLinksCheckbox) == kODFalse)
- GrayDialogItem(dialog, kPartInfoShowLinksText);
- if (GetDialogItemEnable(dialog, kPartInfoStationeryCheckbox) == kODFalse)
- GrayDialogItem(dialog, kPartInfoStationeryText);
- if (GetDialogItemEnable(dialog, kPartInfoActPartRadBtn) == kODFalse)
- GrayDialogItem(dialog, kPartInfoActPartText);
- if (GetDialogItemEnable(dialog, kPartInfoSelPartRadBtn) == kODFalse)
- GrayDialogItem(dialog, kPartInfoSelPartText);
- EndUpdate(dialog);
- }
-
- return CheckKeyScriptChangeFilterProc( dialog, event, itemHit )
- || ODDialogFilterProc( dialog, event, itemHit );
- }
-
- //------------------------------------------------------------------------------
- // EditorAsPopupOrStaticText
- //------------------------------------------------------------------------------
-
- ODStatic void EditorAsPopupOrStaticText( DialogPtr dialog, EditorSet* editorsList, MenuHandle editorMenu)
- {
- ODUShort editorCount = editorsList->GetEditorCount();
-
- if ( editorCount > 1 )
- {
- HideDialogItem(dialog, kPartInfoEditorLabel);
- HideDialogItem(dialog, kPartInfoNoEditorText);
- ShowDialogItem(dialog, kPartInfoEditorPopup);
- }
- else
- {
- Str255 tempStr;
- HideDialogItem(dialog, kPartInfoEditorPopup);
- GetIndString(tempStr, kODInfoUtilStrsID, kODStrIndNoEditors);
- if (editorCount == 0)
- GetIndString(tempStr, kODInfoUtilStrsID, kODStrIndNoEditors);
- else
- GetMenuItemText(editorMenu, 1, tempStr);
- SetDialogFromPStr(dialog, kPartInfoNoEditorText, tempStr, kODFalse, kODFalse);
- ShowDialogItem(dialog, kPartInfoEditorLabel);
- ShowDialogItem(dialog, kPartInfoNoEditorText);
- }
- }
-
- //------------------------------------------------------------------------------
- // DlgChangeKindAndEditor
- //------------------------------------------------------------------------------
-
- ODStatic ODBoolean DlgChangeKindAndEditor (Environment *ev,
- ODPart* part,
- ODType newKind,
- ODEditor newEditor,
- ODNameSpaceManager* nsm,
- ODBoolean* partWarned)
- {
- ODBoolean changed = kODFalse;
- *partWarned = kODFalse;
- TRY
- ChangeKindAndEditor(ev, part, newKind, newEditor, nsm);
- ODStorageUnit* partSU = part->GetStorageUnit(ev);
- if (partSU->Exists(ev, kODPropContents, newKind, 0))
- {
- ODULong unused;
- TempODType preferKind = ODGetISOStrProp(ev, partSU, kODPropPreferredKind, kODISOStr, kODNULL, &unused);
- if ( ODISOStrEqual(preferKind, newKind) )
- changed = kODTrue;
- }
- CATCH_ALL
- if ( ErrorCode() == kODErrAlreadyNotified )
- *partWarned = kODTrue;
- ENDTRY
- return changed;
- }
-
- #ifdef __MWERKS__
- #if GENERATINGPOWERPC
- #if __option(global_optimizer)
- // Turn optimization down to level 4 to avoid out-of-memory errors on this very long fn
- #pragma push
- #pragma optimization_level 1
- #endif
- #endif
- #endif
-
- ODError ShowPartFrameInfo( Environment *ev, ODSession* session,
- ODFacet* facet, ODBoolean allowEditing)
- {
- //ODInfoData *somThis = ODInfoGetData(somSelf);
- //ODInfoMethodDebug("ODInfo","ODInfoShowPartFrameInfo");
-
- short itemHit = kPartInfoCancelBtn;
- ODError error = noErr;
-
- gSession = session;
- InitBindingNamespaceUtils(session);
-
- TRY
-
- gArrowBtnsPictOff =
- ODReadResource(kPICTRsrcType, kArrowBtnsPictOffID);
- gArrowBtnsPictTopOn =
- ODReadResource(kPICTRsrcType, kArrowBtnsPictTopOnID);
- gArrowBtnsPictBotOn =
- ODReadResource(kPICTRsrcType, kArrowBtnsPictBotOnID);
-
-
- DialogPtr dlg = kODNULL; ODVolatile(dlg);
- Handle itemHandle = kODNULL;
- Handle scratchHandle = kODNULL;
- MenuHandle editorMenu = kODNULL;
- MenuHandle kindMenu = kODNULL;
- Rect scratchRect;
- ODSShort itemType;
- Str255 aStr255 = "\p",
- partNameS255 = "\p",
- partCommentsS255 = "\p";
- ODSShort popUpValue = 0;
- ODSShort currentKindItem = 0;
- ODUShort translateToIndex = 0; // Index in translateToList of currently chosen kind
- ODUShort translateToItem = 0; // Item of the Kind popup showing translate to choice
- ODSShort translateItem = 0; // Item of the Kind popup that opens translation dialog
- ODSShort currentEditorItem = 0;
- ODUShort viewval = 0;
-
- ControlHandle kindPopupControlHandle;
- ControlHandle editorPopupControlHandle;
-
- Rect partInfoCategoryRect;
-
- ODBoolean isRootPart = kODFalse;
- ODBoolean frameIsFrozen = kODFalse;
- ODBoolean isRootPartOfDocument = kODFalse;
- ODBoolean showLinks = kODFalse;
- ODBoolean isStationary = kODFalse;
-
- ODNameSpaceManager* nsm = kODNULL;
- ODStorageUnit* partSU = kODNULL;
- ODFrame* frame = kODNULL;
- ODDraft* draft = kODNULL;
- PlatformFile* usersFile = kODNULL; ODVolatile(usersFile);
- ODWindow* window = kODNULL;
- ODSession* session = kODNULL;
- ODWindowState* winstate = kODNULL; ODVolatile(winstate);
-
- ODName* partName = kODNULL; ODVolatile(partName);
-
- ODTypeList* kindList = kODNULL; ODVolatile(kindList);
- ODTypeList* translateToList = kODNULL; ODVolatile(translateToList);
- OrderedCollection* translateFromList = kODNULL; ODVolatile(translateFromList);
- EditorSet* editorsList = kODNULL; ODVolatile(editorsList);
- ODSettingsExtension* settings = kODNULL; ODVolatile(settings);
-
- UserItemUPP DrawBoxItemUPP = kODNULL;
- UserItemUPP DrawThumbnailUPP = kODNULL;
- UserItemUPP DrawIntlStaticTextUPP = kODNULL;
-
- ODScriptCode script = smCurrentScript;
- DialogScriptData dsd;
- ModalFilterUPP modalFilter = kODNULL; ODVolatile(modalFilter);
- DrawProcInfoStruct dpis;
- dpis.category = kODNULL;
- dpis.authorName = kODNULL;
-
- frame = facet->GetFrame(ev);
- TempODPart part = frame->AcquirePart(ev);
-
- ASSERT(!part->IsRealPart(ev), kODErrPartNotWrapper);
-
- session = part->GetStorageUnit(ev)->GetSession(ev);
-
- // Need to load latest nmaps before CUsingLibraryResources
-
- TRY {
- nsm = session->GetNameSpaceManager(ev);
- nsm->SynchNSTable(ev);
- }CATCH_ALL{
- if( ErrorCode()==userCanceledErr)
- RERAISE;
- }ENDTRY
-
- // Need to make sure that the ODReadResource calls happen BEFORE the resource fork is
- // put in use and left in use by the below CUsingLibraryResources.
-
- {CUsingLibraryResources res;
-
- TRY
- winstate = session->GetWindowState(ev);
-
- gFrame = frame;
- partSU = part->GetStorageUnit(ev);
- draft = partSU->GetDraft(ev); // needed for GetPersistentObjectID
- //! is externalization really necessary? the problems is that this cause the document
- //! to be dirty when in most case all the user did was take a peek at the info
- if (HAS_WRITE_ACCESS(draft->GetPermissions(ev)))
- part->Externalize(ev); // Externalize the part so current editor can remove obsolete kinds [cc]
-
- window = facet->GetWindow(ev); // needed for ShouldShowLinks
-
- {
- TempODFrame containingFrame = frame->AcquireContainingFrame(ev);
- isRootPart = ( containingFrame == kODNULL );
- isRootPartOfDocument = isRootPart && window->IsRootWindow(ev);
- }
-
- winstate->DeactivateFrontWindows(ev);
-
- dlg = ODGetNewDialog(ev,kPartInfoDlgID,session);
- THROW_IF_NULL(dlg);
-
- if (allowEditing || !isRootPartOfDocument) { // no Read Only icon if editing allowed or part info
- HideDialogItem(dlg, kPartInfoReadOnlyPict);
- HideDialogItem(dlg, kPartInfoReadOnlyText);
- }
-
- if (isRootPartOfDocument)
- {
- StringHandle str = GetString(kODDocumentInfoWindowName);
- ODLockHandle((ODHandle) str);
- SetWTitle(dlg,(StringPtr)*str);
- ODUnlockHandle((ODHandle) str);
- ReleaseResource((Handle) str);
- usersFile =
- GetPlatformFileFromContainer(ev, draft->GetDocument(ev)->GetContainer(ev));
- }
-
- /* separator lines need to be drawn */
- DrawBoxItemUPP = NewUserItemProc(DrawGrayBoxItem);
-
- SetDialogItemHandle(dlg, kPartInfoSep1, (Handle)DrawBoxItemUPP);
-
- SetDialogItemHandle(dlg, kPartInfoSep2, (Handle)DrawBoxItemUPP);
-
- // Set up Thumbnail
- DrawThumbnailUPP = NewUserItemProc(DrawThumbnail);
- SetDialogItemHandle(dlg, kPartInfoPartThumbnail, (Handle)DrawThumbnailUPP);
-
- // Set up Name
- partName = ODGetPartName(ev, frame, kODNULL);
- if (partName != kODNULL)
- IntlToPStr(partName,(StringPtr)&partNameS255);
- SetDialogFromIText(dlg, kPartInfoNameEditFld, partName, allowEditing, allowEditing);
-
- // set up Comments
- TempODName tempPartComments = ODGetComments(ev, frame, kODNULL);
- SetDialogFromIText(dlg, kPartInfoCommentsEditFld, tempPartComments, allowEditing, kODFalse);
-
- // get binding object & editorID
- ODBinding* binding = session->GetBinding(ev);
- ODPart* partw = part;
- TempODEditor editorID = ((ODPartWrapper*)partw)->GetEditor(ev);
-
- // set up Kind Menu
- TempODType partKind = ODGetKindFromPartSU(ev, partSU); // remember it so so can restore it if necessary
-
- GetDialogItem(dlg, kPartInfoKindPopup, &itemType, (Handle*) &kindPopupControlHandle, &scratchRect);
- kindMenu = GetMenu(kPartInfoKindMenu);
- THROW_IF_NULL(kindMenu);
-
- kindList = NewKindPopup(ev,
- (ODPartWrapper*) partw,
- kindPopupControlHandle,
- kindMenu,
- ¤tKindItem,
- &translateItem);
-
- // set up possible translations
- // These are the translations from any kinds present in the storage unit,
- // plus all other kinds supported by the current editor.
- translateToList = session->GetStorageSystem(ev)->CreateTypeList(ev, (ODTypeList*) kODNULL);
- translateFromList = new OrderedCollection;
- THROW_IF_NULL(translateFromList);
- TranslateValueTypes(kindList, translateToList, translateFromList, session);
-
- // set up Category user item
- dpis.category = ODGetCategory(ev, part, nsm);
-
- SetDialogItemHandle(dlg, kPartInfoCategoryFld, (Handle)DrawThumbnailUPP);
-
- #ifdef _APPLEGUIDE_READY_
- DialogSetUpAppleGuide( dlg, kPartInfoAppleGuideButton );
- #endif
- // set up Editor Menu
- GetDialogItem(dlg, kPartInfoEditorPopup, &itemType, (Handle*) &editorPopupControlHandle, &scratchRect);
- editorMenu = GetMenu(kPartInfoEditorMenu);
- THROW_IF_NULL(editorMenu);
-
- if (ODISOStrNCompare(editorID, kODBlackBoxHandlerOfLastResort, ODISOStrLength(editorID)) == 0)
- { // if no part but editor available now then rebind
- TempODType bestKind = BestContentKind(partSU);
- TempODEditor preferredEditor = binding->ChooseEditorForPart(ev, partSU, bestKind);
- if (ODISOStrNCompare(preferredEditor, kODBlackBoxHandlerOfLastResort, ODISOStrLength(editorID)) != 0)
- {
- // we are rebinding, so it is OK to eat the error
- TRY
- ChangeEditor(part, preferredEditor);
- ODPart* partw = part;
- ODDisposePtr((ODPtr) editorID);
- editorID = kODNULL;
- editorID = ((ODPartWrapper*)partw)->GetEditor(ev);
- CATCH_ALL
- ENDTRY
- }
- }
-
- editorsList = NewEditorPopup(ev,
- (ODPartWrapper*) partw,
- editorPopupControlHandle,
- editorMenu,
- kindList,
- currentKindItem,
- editorID,
- ¤tEditorItem
- );
-
- EditorAsPopupOrStaticText(dlg, editorsList, editorMenu);
-
- if (!allowEditing) {
- // disable everything but the current editor if no editing allowed
- for (ODUShort i=1;i<=CountMItems(editorMenu);i++) {
- if (currentEditorItem != i)
- DisableItem(editorMenu, i);
- }
- // disable everything but the current kind if no editing allowed
- for (ODUShort j=1;j<=CountMItems(kindMenu);j++) {
- if (currentKindItem != j)
- DisableItem(kindMenu, j);
- }
- }
-
- // set up size
- ODULong size = ODGetPOSize(ev, part);
- SetSizeText(dlg, kPartInfoSizeFld, size);
-
- // set up Create and Modify date and time
- SetModCreatDateTimeText( ev, dlg, partSU );
-
- // set up by
- SetDialogItemHandle(dlg, kPartInfoByFld, (Handle)DrawThumbnailUPP);
- dpis.authorName = ODGetModifiedBy( ev, partSU, kODNULL );
-
- WASSERT( !GetWRefCon(dlg) ); // will be null if no one's using it
- SetWRefCon(dlg, (long)&dpis);
-
- // set up the scripting ID
- // If the frame is non-persistent, show the part's scripting ID.
- // Note that the scripting ID is not the same as the object ID returned by the
- // persistent object's GetID method.
- ODPersistentObjectID id;
- if ( frame->GetStorageUnit(ev) != kODNULL )
- {
- id = draft->GetPersistentObjectID(ev,
- (ODPersistentObject*) frame,
- kODFrameObject);
- }
- else
- {
- id = draft->GetPersistentObjectID(ev,
- (ODPersistentObject*) part,
- kODPartObject);
- }
- SetNumText(dlg, kPartInfoIDFld, (ODSLong)id);
-
- // set up viewas
- GetDialogItem(dlg, kPartInfoViewAsPopup, &itemType, &itemHandle, &scratchRect);
-
- ODTypeToken view = frame->GetViewType(ev);
-
- if (view == session->Tokenize(ev, kODViewAsFrame))
- viewval = 1;
- else if (view == session->Tokenize(ev, kODViewAsLargeIcon))
- viewval = 2;
- else if (view == session->Tokenize(ev, kODViewAsSmallIcon))
- viewval = 3;
- else if (view == session->Tokenize(ev, kODViewAsThumbnail))
- viewval = 4;
-
- SetControlValue((ControlHandle)itemHandle, viewval);
- MenuHandle viewAsMenu = ((PopupPrivateData*)(*(**(ControlHandle)itemHandle).contrlData))->mHandle;
- if ((isRootPartOfDocument) || (!allowEditing)) {
- // disable everything but the current selection if no editing or root frame (current select is frame)
- for (ODUShort i=1;i<=4;i++) {
- if (viewval != i)
- DisableItem(viewAsMenu, i);
- }
- }
- else {
- // enable them just in case they were disabled
- EnableItem(viewAsMenu, 2);
- EnableItem(viewAsMenu, 3);
- EnableItem(viewAsMenu, 4);
- }
-
- if (isRootPartOfDocument) {
- HideDialogItem(dlg, kPartInfoBundledText);
- HideDialogItem(dlg, kPartInfoActPartRadBtn);
- HideDialogItem(dlg, kPartInfoActPartText);
- HideDialogItem(dlg, kPartInfoSelPartRadBtn);
- HideDialogItem(dlg, kPartInfoSelPartText);
-
- // set up stationery from aFrame and its part
- isStationary = ODGetIsStationery(ev, frame);
- SetDialogBoolean(dlg, kPartInfoStationeryCheckbox, isStationary, allowEditing);
-
- // set up show links from the window
- showLinks = window->ShouldShowLinks(ev);
- SetDialogBoolean(dlg, kPartInfoShowLinksCheckbox, showLinks, allowEditing);
- }
- else {
- HideDialogItem(dlg, kPartInfoShowLinksCheckbox);
- HideDialogItem(dlg, kPartInfoShowLinksText);
- HideDialogItem(dlg, kPartInfoStationeryCheckbox);
- HideDialogItem(dlg, kPartInfoStationeryText);
- HideDialogItem(dlg, kPartInfoMemorySizeButton);
-
- // set up frozen
- frameIsFrozen = frame->IsFrozen(ev);
- SetDialogBoolean(dlg, kPartInfoSelPartRadBtn, frameIsFrozen, allowEditing);
- SetDialogBoolean(dlg, kPartInfoActPartRadBtn, !frameIsFrozen, allowEditing);
- }
-
- // set up Settings…
- if (part->HasExtension(ev, kODSettingsExtension))
- {
- settings = (ODSettingsExtension*)part->AcquireExtension(ev,kODSettingsExtension);
- }
- else
- {
- HideDialogItem(dlg, kPartInfoSettingsButton);
- }
-
- // Display the dialog
- {
- TempODMenuBar currentMenuBar = winstate->AcquireCurrentMenuBar(ev);
- ODDialogBegin(ev, session, currentMenuBar, dlg);
- }
-
- ODUseDialogScriptData( &dsd, dlg );
- ODIText* tmpText = PickOneIText( tempPartComments, partName );
- if ( tmpText )
- dsd.SetScriptAndLockKeyboard( script = GetRealScriptCode(tmpText) );
-
- ShowWindow(dlg);
- modalFilter = NewModalFilterProc(CallCheckScriptFirstThenStdFilterProc);
- SetPort(dlg);
- SetDialogTextStyle(dlg, kPartInfoDlgID, script);
- ODBoolean nameModified = kODFalse;
- ODBoolean commentModified = kODFalse;
-
- do {
- // Remember the currently selected kind
- currentKindItem = (ODSShort) GetControlValue(kindPopupControlHandle);
- ModalDialog(modalFilter, &itemHit);
- switch (itemHit) {
- case kPartInfoActPartText:
- itemHit = kPartInfoActPartRadBtn;
- break;
- case kPartInfoSelPartText:
- itemHit = kPartInfoSelPartRadBtn;
- break;
- case kPartInfoShowLinksText:
- itemHit = kPartInfoShowLinksCheckbox;
- break;
- case kPartInfoStationeryText:
- itemHit = kPartInfoStationeryCheckbox;
- break;
- default: break;
- }
- GetDialogItem(dlg, itemHit, &itemType, &itemHandle, &scratchRect);
- switch (itemHit) {
- case kPartInfoActPartRadBtn:
- case kPartInfoSelPartRadBtn:
- if (!GetControlValue((ControlHandle)itemHandle)) {
- SetControlValue((ControlHandle)itemHandle,1);
- itemHit = (itemHit == kPartInfoActPartRadBtn) ?
- kPartInfoSelPartRadBtn : kPartInfoActPartRadBtn;
- GetDialogItem(dlg, itemHit, &itemType, &itemHandle, &scratchRect);
- SetControlValue((ControlHandle)itemHandle,0);
- }
- break;
- case kPartInfoStationeryCheckbox:
- case kPartInfoShowLinksCheckbox:
- SetControlValue((ControlHandle)itemHandle,
- 1-GetControlValue((ControlHandle)itemHandle));
- break;
- case kPartInfoSettingsButton:
- if (settings != kODNULL) {
- ActivateAllControls(dlg, kODFalse); // deactivate control
- settings->ShowSettings(ev,facet);
- ActivateAllControls(dlg, kODTrue); // reactivate control
- }
- break;
- case kPartInfoMemorySizeButton:
- ActivateAllControls(dlg, kODFalse); // deactivate control
- ShowSizeDialog(ev, session, usersFile, partNameS255, allowEditing);
- ActivateAllControls(dlg, kODTrue); // reactivate control
- break;
- case kPartInfoKindPopup:
- popUpValue = GetControlValue(kindPopupControlHandle);
- if (popUpValue == translateItem)
- {
- ODUShort selectedIndex;
- ODSShort editorItem = (ODSShort) GetControlValue(editorPopupControlHandle);
- TempODEditor initialEditorID = GetThisEditorFromList(editorItem, editorsList);
- TempODEditor tempEditorID = kODNULL;
- ODEditor newEditorID = kODNULL;
-
- // Return the kind popup to its current value
- SetPopupControlValue(kindPopupControlHandle, currentKindItem);
-
- session->GetWindowState(ev)->DeactivateFrontWindows(ev);
-
- ODBoolean doTranslate = session->GetTranslation(ev)->ShowTranslateDialog(
- ev,
- translateToList,
- translateToIndex,
- &selectedIndex,
- initialEditorID,
- kODTrue,
- &newEditorID);
- tempEditorID = newEditorID; // Dispose, eventually
- if ( doTranslate )
- {
- // Add translationKind to the list just above "Translate to…",
- // and make it the current selection.
- translateToIndex = selectedIndex;
-
- TempODType oldKind = GetThisKindFromList(currentKindItem, kindList);
- TempODType translationKind = GetThisKindFromList(translateToIndex, translateToList);
- AddTranslationKindToMenu(translationKind,
- kindMenu,
- translateItem-1,
- (translateToItem == 0),
- session);
-
- // Add the translationKind to the end of kindList
- if ( translateToItem != 0 )
- {
- TempODType currentTranslationKind = GetThisKindFromList(translateToItem, kindList);
- kindList->Remove(ev, currentTranslationKind);
- }
- kindList->AddLast(ev, translationKind);
-
- if ( translateToItem == 0 )
- {
- translateToItem = translateItem;
- translateItem += 1;
- }
-
- SetPopupControlValue(kindPopupControlHandle, translateToItem);
-
- editorsList->RemoveAllEditors();
- ODBoolean anyEditors = SetupEditorMenu(translationKind,
- editorsList,
- editorMenu,
- editorPopupControlHandle,
- session,
- partSU);
-
- // Select editorID in the list (it SHOULD be in the list!)
- ODSShort editorItem = IndexOfEditorInList(editorsList, newEditorID);
- if ( editorItem != 0 )
- SetPopupControlValue(editorPopupControlHandle, editorItem);
-
- EditorAsPopupOrStaticText(dlg, editorsList, editorMenu);
-
- TempODType newCat = ODGetFirstCategoryOfKind(ev, translationKind, nsm);
- TempODType oldCat = ODGetFirstCategoryOfKind(ev, oldKind, nsm);
- if ( !ODISOStrEqual(newCat, oldCat) )
- {
- DisposeIText(dpis.category);
- dpis.category = ODGetCatFromKind(ev, translationKind, nsm);
- InvalRect(&partInfoCategoryRect);
- }
- }
- }
- else if ( popUpValue != currentKindItem )
- {
- // Determine the old and new kinds for later
- TempODType oldKind = GetThisKindFromList(currentKindItem, kindList);
- TempODType newKind = GetThisKindFromList(popUpValue, kindList);
-
- // Remember the currently selected editor
- ODSShort editorItem = (ODSShort) GetControlValue(editorPopupControlHandle);
- TempODEditor lastEditorID = GetThisEditorFromList(editorItem, editorsList);
-
- editorsList->RemoveAllEditors();
- SetupEditorMenu(newKind,
- editorsList,
- editorMenu,
- editorPopupControlHandle,
- session,
- partSU);
-
- // Reselect the last editor if it supports the new kind
- ODSShort newEditorItem = 0;
- if ( EditorSupportsKind(nsm, lastEditorID, newKind) )
- newEditorItem = IndexOfEditorInList(editorsList, lastEditorID);
- if ( newEditorItem != 0 )
- SetPopupControlValue(editorPopupControlHandle, newEditorItem);
- // else
- // Draw1Control(editorPopupControlHandle);
- EditorAsPopupOrStaticText(dlg, editorsList, editorMenu);
-
- // Change the category string if changed
- TempODType oldCat = ODGetFirstCategoryOfKind(ev, oldKind, nsm);
- TempODType newCat = ODGetFirstCategoryOfKind(ev, newKind, nsm);
- if ( !ODISOStrEqual(newCat, oldCat) )
- {
- DisposeIText(dpis.category);
- dpis.category = ODGetCatFromKind(ev, newKind, nsm);
- SetPort(dlg);
- InvalRect(&partInfoCategoryRect);
- }
- }
- break;
-
- case kPartInfoCancelBtn:
- if (allowEditing) { // cancel, make sure we restore all the values
- TempODName newPartName = GetITextFromDialog(dlg, kPartInfoNameEditFld,
- dsd.Script(), dsd.Language());
- if (newPartName) {
- if (nameModified && !ITextStrEqual(newPartName, partName)) {
- ODSetPartName(ev, frame, partName, kAEAsk);
- if (isRootPart)
- SetProcessName(partName);
- }
- }
- TempODName newPartComment = GetITextFromDialog(dlg, kPartInfoCommentsEditFld,
- dsd.Script(), dsd.Language());
- if (newPartComment) {
- if (commentModified && !ITextStrEqual(newPartComment, tempPartComments))
- ODSetComments(ev, frame, tempPartComments);
- }
-
- TempODType newPartKind = ODGetKindFromPartSU(ev, partSU);
- if (!ODISOStrEqual(newPartKind, partKind))
- ODSetPreferredKindProps(partSU, partKind);
- }
- break;
-
- case kPartInfoOKBtn:
- if (allowEditing)
- {
- script = dsd.Script();
- ODLangCode lang = dsd.Language();
-
- // update Name
-
- ODIText *newPartName = GetITextFromDialog(dlg, kPartInfoNameEditFld,
- script, lang);
- if (newPartName) {
- ODError setNameError = noErr;
- if (!ITextStrEqual(newPartName, partName)) {
- ActivateAllControls(dlg, kODFalse); // deactivate control
- nameModified = kODTrue;
- setNameError = ODSetPartNameReturnError(ev, frame, newPartName, kAEAsk);
- if (isRootPart)
- SetProcessName(newPartName);
- if (setNameError != noErr) {
- if (setNameError != userCanceledErr)
- (void) ShowAlert(ev, kPartInfoInvalidNameAlertID, kODNULL, session);
- itemHit = kPartInfoNameEditFld;
- SelectDialogItemText(dlg, kPartInfoNameEditFld, 0, GetITextStringLength(newPartName));
- }
- ActivateAllControls(dlg, kODTrue); // reactivate control
- }
- DisposeIText(newPartName);
- if (setNameError != noErr)
- break;
- }
-
- // update Comments
- ODIText *newPartComment = GetITextFromDialog(dlg, kPartInfoCommentsEditFld,
- script, lang);
- if (newPartComment) {
- if (!ITextStrEqual(newPartComment, tempPartComments)) {
- commentModified = kODTrue;
- ODSetComments(ev, frame, newPartComment);
- TempODName actualPartComments = ODGetComments(ev, frame, kODNULL);
- if (!ITextStrEqual(newPartComment, actualPartComments)) {
- itemHit = kPartInfoCommentsEditFld;
- SetDialogFromIText(dlg, kPartInfoCommentsEditFld, actualPartComments, allowEditing, kODTrue);
- DisposeIText(newPartComment);
- ActivateAllControls(dlg, kODFalse); // deactivate control
- (void) ShowAlert(ev, kPartInfoLongCommentAlertID, kODNULL, session);
- ActivateAllControls(dlg, kODTrue); // reactivate control
- break;
- }
- }
- DisposeIText(newPartComment);
- }
-
- // update Kind or Editor
- currentKindItem = (ODSShort) GetControlValue(kindPopupControlHandle);
- TempODType newKind = GetThisKindFromList(currentKindItem, kindList);
-
- ODSShort editorItem = (ODSShort) GetControlValue(editorPopupControlHandle);
- TempODEditor newEditorID = GetThisEditorFromList(editorItem, editorsList);
-
- TempODEditor partEditor = GetCurrentEditorForPart(part);
-
- if ( ((ODType) newKind) && ((ODEditor) newEditorID) && !ODISOStrEqual(newKind, partKind) )
- {
- ODBoolean changeSuccessful, partWarned;
- if ( (currentKindItem == translateToItem) && (translateToItem > 0) )
- {
- ODUShort translateFromIndex =
- GetOrderedCollectionElement(translateFromList, translateToIndex);
- TempODType fromKind = GetThisKindFromList(translateFromIndex, kindList);
-
- // If fromKind does not yet exist, force part to change to that kind.
- // Otherwise, force the part to externalize any changes to its storage unit.
- ODBoolean forceChangeKind = !partSU->Exists(ev, kODPropContents, (ODType) fromKind, 0);
- if ( forceChangeKind )
- part->ChangeKind(ev, (ODType) fromKind);
- else
- part->Externalize(ev);
-
- partSU->Focus(ev, kODPropContents, kODPosUndefined, (ODType) fromKind, 0, kODPosUndefined);
- TempODStorageUnitView fromView = partSU->CreateView(ev);
-
- partSU->Focus(ev, kODPropContents, kODPosAll, kODTypeAll, 0, kODPosUndefined);
-
- partSU->AddValue(ev, (ODType) newKind);
- TempODStorageUnitView toView = partSU->CreateView(ev);
-
- TRY
- session->GetTranslation(ev)->TranslateView(ev, fromView, toView);
- CATCH_ALL
- // Remove the translated value type
- if ( ODSUExistsThenFocus(ev, partSU, kODPropContents, newKind) )
- partSU->Remove(ev);
- // If translation fails after changing the kind, change kind back
- if ( forceChangeKind )
- part->ChangeKind(ev, partKind);
- RERAISE;
- ENDTRY
- changeSuccessful = DlgChangeKindAndEditor(ev, part, newKind,
- newEditorID, nsm, &partWarned );
- }
- else
- changeSuccessful = DlgChangeKindAndEditor(ev, part, newKind,
- newEditorID, nsm, &partWarned );
- if ( !changeSuccessful )
- {
- if ( !partWarned )
- {
- Str255 newKindStr;
- ODName* name = kODNULL;
- if (GetUserKindFromKind(nsm, newKind, &name))
- {
- IntlToPStr(name, newKindStr);
- DisposeIText( name );
- ParamText(newKindStr, kODNULL, kODNULL, kODNULL);
- }
- ActivateAllControls(dlg, kODFalse); // deactivate control
- (void) ShowAlert(ev, kPartInfoCannotChangeAlertID, kODNULL, session);
- ActivateAllControls(dlg, kODTrue); // reactivate control
- }
- itemHit = -1;
- break;
- }
- }
- else if ( ((ODEditor) newEditorID) && !ODISOStrEqual(newEditorID, partEditor) )
- {
- ODReleaseObject(ev, settings); // editor may delete its settings, so release it first
- ChangeEditor(part, newEditorID);
- }
-
- if (isRootPartOfDocument) {
- // update Stationery
- ODBoolean checkBoxValue = GetDialogBoolean(dlg, kPartInfoStationeryCheckbox);
- if (checkBoxValue != isStationary)
- ODSetIsStationery(ev, frame, checkBoxValue);
-
- // update Show Links
- checkBoxValue = GetDialogBoolean(dlg, kPartInfoShowLinksCheckbox);
- if (checkBoxValue != showLinks)
- SetAllWindowShowLinks(ev, winstate, checkBoxValue);
- // window->SetShouldShowLinks(ev,checkBoxValue);
- }
- else {
- // update Frozen
- ODBoolean checkBoxValue = GetDialogBoolean(dlg, kPartInfoSelPartRadBtn);
- if (checkBoxValue != frameIsFrozen)
- frame->SetFrozen(ev, checkBoxValue);
- }
-
- // update ViewAs
- GetDialogItem(dlg, kPartInfoViewAsPopup, &itemType, &itemHandle, &scratchRect);
- popUpValue = GetControlValue((ControlHandle)itemHandle);
- if (popUpValue != viewval )
- {
- switch (popUpValue)
- {
- case 1: // view as frame
- frame->ChangeViewType(ev, session->Tokenize(ev, kODViewAsFrame));
- break;
- case 2: // view as large icon
- frame->ChangeViewType(ev, session->Tokenize(ev, kODViewAsLargeIcon));
- break;
- case 3: // view as small icon
- frame->ChangeViewType(ev, session->Tokenize(ev, kODViewAsSmallIcon));
- break;
- case 4: // view as thumbnail
- frame->ChangeViewType(ev, session->Tokenize(ev, kODViewAsThumbnail));
- break;
- default:
- break;
- }
- }
-
- }
- break;
- #ifdef _APPLEGUIDE_READY_
- case kPartInfoAppleGuideButton:
- OpenAppleGuide( ODGetIndShort( kODShellGuideSearchIndices,
- isRootPartOfDocument?
- kODShellGuideStringIndexDocument:
- kODShellGuideStringIndexPartFrame ) );
- break;
- #endif
- default: break;
- }
- } while ((itemHit != kPartInfoOKBtn) && (itemHit != kPartInfoCancelBtn));
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- ODDialogEnd();
-
- DeleteMenu(kPartInfoEditorMenu);
- ReleaseResource((Handle)editorMenu);
- DeleteMenu(kPartInfoKindMenu);
- ReleaseResource((Handle)kindMenu);
-
- DisposeIText(dpis.category);
- DisposeIText(dpis.authorName);
-
- DisposeIText(partName);
-
- ODReleaseObject(ev, settings);
- ODDeleteObject (editorsList);
- ODDeleteObject (kindList);
- ODDeleteObject (translateToList);
- ODDeleteObject (translateFromList);
- ODDeleteObject (usersFile);
-
- DisposeRoutineDescriptor(DrawBoxItemUPP);
- if (DrawThumbnailUPP)
- DisposeRoutineDescriptor(DrawThumbnailUPP);
- ODDisposeRoutineDescriptor(DrawIntlStaticTextUPP);
-
- if (dlg)
- DisposeDialog(dlg);
-
- DisposeRoutineDescriptor( modalFilter );
-
- } // EndUsingResources of CUsingLibraryResources.
-
- ODDisposeHandle(gArrowBtnsPictOff);
- ODDisposeHandle(gArrowBtnsPictTopOn);
- ODDisposeHandle(gArrowBtnsPictBotOn);
-
- ODReleaseObject(ev, part);
-
- winstate->ActivateFrontWindows(ev);
-
- if ((error == noErr) && (itemHit == kPartInfoCancelBtn))
- error = userCanceledErr;
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- }
-
- #ifdef MWERKS
- #if GENERATINGPOWERPC
- #if __option(global_optimizer)
- // Restore settings [see before fn]
- #pragma pop
- #endif
- #endif
- #endif
-
-
- //-------------------------------------------------------------------------------------
- // Kind Menu manipulation functions
- //-------------------------------------------------------------------------------------
- // copied from LinkDlgs.cpp (!with changes by TÇ)
- //------------------------------------------------------------------------------
- //------------------------------------------------------------------------------
- // GenerateEditorsList
- //------------------------------------------------------------------------------
-
- ODStatic void GenerateEditorsList(ODSShort currentKindItem,
- ODTypeList* kindsList,
- EditorSet* editorsList,
- ODNameSpaceManager* nsm)
- {
- ODSShort i = 1;
- Environment* ev = somGetGlobalEnvironment();
-
- //clear editorsList
- editorsList->RemoveAllEditors();
-
- ODTypeListIterator* kindIter = kindsList->CreateTypeListIterator(ev);
- for (ODType kind = kindIter->First(ev);
- kindIter->IsNotComplete(ev);
- kind = kindIter->Next(ev), i++)
- {
- if (i == currentKindItem)
- GetAllEditorsForKind( nsm, kind, editorsList );
- ODDisposePtr(kind);
- }
- ODDeleteObject( kindIter );
- }
-
- //------------------------------------------------------------------------------
- // SetModCreatDateTimeText
- //------------------------------------------------------------------------------
- ODStatic void SetModCreatDateTimeText(Environment* ev, DialogPtr dlg,
- ODStorageUnit* partSU )
- {
- Str255 createDateString = "\p";
- Str255 createTimeString = "\p";
- Str255 modDateString = "\p";
- Str255 modTimeString = "\p";
-
- ODULong createDateTime = ODGetCreationDate(ev, partSU);
- if ( createDateTime == 0 )
- {
- StringHandle str = GetString(kODPartInfoStrUnknownID);
- if ( str != kODNULL )
- {
- ODLockHandle((ODHandle) str);
- ODBlockMove((ODPtr) *str, (ODPtr) createDateString, (ODULong) (*str[0])+1);
- ODUnlockHandle((ODHandle) str);
- ReleaseResource((Handle) str);
- }
- else
- {
- createDateString[0] = (char) 0;
- }
- createTimeString[0] = (char) 0;
- }
- else
- {
- DateString(createDateTime, abbrevDate, createDateString, kODNULL);
- TimeString(createDateTime, kODFalse, createTimeString, kODNULL);
- }
-
- ODULong modDateTime = ODGetModificationDate(ev, partSU);
-
- if ( modDateTime == 0 )
- {
- StringHandle str = GetString(kODPartInfoStrUnknownID);
- if ( str != kODNULL )
- {
- ODLockHandle((ODHandle) str);
- ODBlockMove((ODPtr) *str, (ODPtr) modDateString, (ODULong) (*str[0])+1);
- ODUnlockHandle((ODHandle) str);
- ReleaseResource((Handle) str);
- }
- else
- {
- modDateString[0] = (char) 0;
- }
- modTimeString[0] = (char) 0;
- }
- else
- {
- DateString(modDateTime, abbrevDate, modDateString, kODNULL);
- TimeString(modDateTime, kODFalse, modTimeString, kODNULL);
- }
-
- // don't do this! The replace dialog also uses ParamText so that we get
- // garbage when redrawing after calling it.
- // ParamText( createDateString, createTimeString, modDateString, modTimeString);
-
- ParamDlgText( dlg, kPartInfoCreatedFld, "^0", createDateString, "^1", createTimeString );
- ParamDlgText( dlg, kPartInfoModifiedFld, "^2", modDateString, "^3", modTimeString );
- }
-
- //------------------------------------------------------------------------------
- // ParamDlgText
- //------------------------------------------------------------------------------
- ODStatic void ParamDlgText( DialogPtr dlg, short item, char* search1, Str255 str1,
- char* search2, Str255 str2 )
- {
- short itemType;
- Handle itemHandle;
- Rect itemRect;
-
- GetDialogItem( dlg, item, &itemType, &itemHandle, &itemRect );
- if ( search1 )
- {
- WASSERT( strlen(search1) == 2 );
- (void)Munger( itemHandle, 0, search1, 2, &str1[1], str1[0] );
- }
- if ( search2 )
- {
- WASSERT( strlen(search2) == 2 );
- (void)Munger( itemHandle, 0, search2, 2, &str2[1], str2[0] );
- }
- }
-
- //------------------------------------------------------------------------------
- // SetSizeText
- //------------------------------------------------------------------------------
- ODStatic void SetSizeText(DialogPtr dlg, ODSShort item, ODULong size)
- {
- Str255 text;
- Str63 sizeString;
- short strTemplateID;
-
- if ( size < 1024 )
- {
- NumToString(size, sizeString);
- strTemplateID = kODPartInfoSizeInBytes;
- }
- else
- {
- // Round off to nearest K
- size = (size + 512) / 1024;
- NumToString(size, sizeString);
- strTemplateID = kODPartInfoSizeInK;
- }
-
- //CUsingLibraryResources r;
- ReplaceIntoString(strTemplateID, sizeString, kODNULL, text);
-
- SetDialogFromPStr(dlg, item, text, kODFalse, kODFalse);
- }
-
-
- //------------------------------------------------------------------------------
- // SetModifiedByText
- //------------------------------------------------------------------------------
-
- ODStatic void SetModifiedByText(DialogPtr dlg, ODSShort item, ODName* name)
- {
- short itemType;
- Handle itemHandle;
- Rect itemRect;
-
- // I suspect that we'll have to change the model here to support
- // two-byte text. Rather than stick the text into the dialog
- // before it's drawn and then let the Dialog Mgr. draw it with
- // no information about what script to use, we need to draw it
- // ourselves via a drawproc that will get called each time it's
- // redrawn. Confirm this suspicion before doing the work....
-
- // Str255 text = "\p";
-
- // if (name)
- // IntlToPStr(name,(StringPtr)&text);
- GetDialogItem(dlg, item, &itemType, &itemHandle, &itemRect);
- PaintRect( &itemRect );
- // SetDialogItemText(itemHandle,text);
-
- if (name)
- DrawITextInDlogBox(name, &itemRect, dlg, kODTrue);
- }
-
- //------------------------------------------------------------------------------
- // DrawThumbnail
- // Now draws thumbnail *and* the modified by name.
- //------------------------------------------------------------------------------
-
- pascal void DrawThumbnail(DialogPtr theDialog, short theItem)
- {
- Rect frameRect;
- Handle scratchHandle = kODNULL;
- short scratchKind;
- ODPtr theIcon = kODNULL;
- ODIconFamily iconSuite = kODNULL;
- Environment* ev = somGetGlobalEnvironment();
-
- GetDialogItem(theDialog, theItem, &scratchKind, &scratchHandle, &frameRect);
- DrawProcInfo dpi = (DrawProcInfo)GetWRefCon(theDialog);
-
- switch( theItem )
- {
- case kPartInfoPartThumbnail:
- iconSuite = ODGetIconFamily(ev, gFrame );
- if (iconSuite)
- {
- IconAlignmentType align = atAbsoluteCenter;
- IconTransformType transform = ttNone;
- ODError result = PlotIconSuite( &frameRect, align, transform,
- (Handle)iconSuite );
- DisposeIconSuite( (Handle)iconSuite,kODTrue );
- }
- else
- FrameRect(&frameRect);
- break;
- case kPartInfoByFld:
- if (dpi->authorName)
- DrawITextInDlogBox( dpi->authorName, &frameRect, theDialog, kODTrue );
- break;
- case kPartInfoCategoryFld:
- if (dpi->category)
- DrawITextInDlogBox( dpi->category, &frameRect, theDialog, kODTrue );
- break;
- }
- }
-
- //------------------------------------------------------------------------------
- // DeleteAllMenuItems
- //------------------------------------------------------------------------------
- ODStatic void DeleteAllMenuItems(MenuHandle theMenu)
- {
- ODUShort i;
-
- for (i = CountMItems(theMenu); i > 0; --i)
- {
- DeleteMenuItem(theMenu, i);
- }
- }
-
- //------------------------------------------------------------------------------
- // Document Heap Dialog Functions
- //------------------------------------------------------------------------------
-
- //=========================================================================
- // Constants
- //=========================================================================
-
- static const ODULong kDocHeapSizeDelta = 32;
-
-
- #define k1K 1024
-
-
- //=========================================================================
- // DocHeapArrowButtonsFilterProc
- //=========================================================================
-
- pascal Boolean
- DocHeapArrowButtonsFilterProc(DialogPtr dialog, EventRecord *event, short *itemHit);
-
- //=========================================================================
- // ShowSizeDialog
- //=========================================================================
-
- ODStatic void ShowSizeDialog(Environment* ev, ODSession* session,
- PlatformFile* file, Str255 partNameS255, ODBoolean allowEditing)
- {
- THROW_IF_NULL(ev);
- THROW_IF_NULL(session);
- THROW_IF_NULL(file);
-
- DialogPtr dlg = kODNULL;
- short itemHit = kDocHeapCancelBtn;
- Handle itemHandle = kODNULL;
- Handle scratchHandle = kODNULL;
- Rect scratchRect;
-
- dlg = ODGetNewDialog(ev,kDocHeapDlgID,session);
-
- THROW_IF_NULL(dlg);
- SetPort(dlg);
- SetDialogTextStyle(dlg, kDocHeapDlgID, smCurrentScript);
-
- #ifdef _APPLEGUIDE_READY_
- DialogSetUpAppleGuide( dlg, kDocHeapAppleGuideButton );
- #endif
-
- // Set the Document name text field
- SetDialogFromPStr(dlg, kDocHeapDocumentNameFld, partNameS255, kODFalse, kODFalse);
-
- // Set the OpenDoc Default Size
- ODULong curDefaultSize = DHGetODDefaultHeapSize();
- if (curDefaultSize < kDocStubMinHeapSize/k1K)
- curDefaultSize = kDocStubMinHeapSize/k1K;
- SetNumText(dlg, kDocHeapDefaultSizeFld, curDefaultSize);
-
- // Set the Document Preferred Size
- ODULong curPreferredSize =
- DHGetDocumentPreferredHeapSize(file);
- ODBoolean curDefaultSizeChosen = (curPreferredSize == 0);
- if (curDefaultSizeChosen)
- curPreferredSize = curDefaultSize;
-
- SetNumText(dlg, kDocHeapPreferdSizeFld, curPreferredSize);
-
- // set up the radio button, if editing not allowed disable the other option
- SetDialogBoolean(dlg, kDocHeapDefaultSizeRadBtn, curDefaultSizeChosen, allowEditing | curDefaultSizeChosen);
- SetDialogBoolean(dlg, kDocHeapPreferdSizeRadBtn, !curDefaultSizeChosen, allowEditing | !curDefaultSizeChosen);
-
- ODULong newPreferredSize = curPreferredSize;
- ODULong newDefaultSize = curDefaultSize;
- ODBoolean newDefaultSizeChosen = curDefaultSizeChosen;
-
- if (!allowEditing) {
- // no editing, then hide the arrow buttons for changing the size
- HideDialogItem(dlg, kDocHeapDefaultSizeTopBtnRect);
- HideDialogItem(dlg, kDocHeapPreferdSizeTopBtnRect);
- HideDialogItem(dlg, kDocHeapDefaultSizeBotBtnRect);
- HideDialogItem(dlg, kDocHeapPreferdSizeBotBtnRect);
- HideDialogItem(dlg, kDocHeapPreferdSizeBtns);
- HideDialogItem(dlg, kDocHeapDefaultSizeBtns);
- HideDialogItem(dlg, kDocHeapMakeChangeStatText);
- HideDialogItem(dlg, kDocHeapChangeNextLaunchStatText);
- }
-
- ModalFilterUPP docHeapSizeUPP = NewModalFilterProc(&DocHeapArrowButtonsFilterProc);
-
- // Display the dialog
- ShowWindow(dlg);
- do {
- ODULong* newSizePtr;
- ODSShort itemType;
- ODULong delta;
- ODSShort btnsItemNum;
- ModalDialog(docHeapSizeUPP, &itemHit);
- GetDialogItem(dlg, itemHit, &itemType, &itemHandle, &scratchRect);
- switch (itemHit) {
- case kDocHeapDefaultSizeTopBtnRect:
- case kDocHeapPreferdSizeTopBtnRect:
- case kDocHeapDefaultSizeBotBtnRect:
- case kDocHeapPreferdSizeBotBtnRect:
- newDefaultSizeChosen =
- (itemHit == kDocHeapDefaultSizeTopBtnRect ||
- itemHit == kDocHeapDefaultSizeBotBtnRect);
-
- btnsItemNum =
- newDefaultSizeChosen ?
- kDocHeapDefaultSizeBtns :
- kDocHeapPreferdSizeBtns ;
-
- GetDialogItem(dlg, btnsItemNum, &itemType, &itemHandle, &scratchRect);
- SetDialogItem(dlg, btnsItemNum, picItem, gArrowBtnsPictOff,
- &scratchRect);
-
- delta = kDocHeapSizeDelta;
- if (itemHit == kDocHeapDefaultSizeBotBtnRect ||
- itemHit == kDocHeapPreferdSizeBotBtnRect)
- delta = -kDocHeapSizeDelta;
-
- newSizePtr =
- newDefaultSizeChosen ?
- &newDefaultSize :
- &newPreferredSize ;
-
- (*newSizePtr) += delta;
- if (*newSizePtr < kDocStubMinHeapSize/k1K)
- *newSizePtr = kDocStubMinHeapSize/k1K;
-
- SetNumText(dlg,
- newDefaultSizeChosen ? kDocHeapDefaultSizeFld : kDocHeapPreferdSizeFld,
- *newSizePtr);
-
- gSizeDialogClickAt =
- (itemHit == kDocHeapDefaultSizeTopBtnRect ||
- itemHit == kDocHeapDefaultSizeBotBtnRect) ?
- kDocHeapDefaultSizeBtns :
- kDocHeapPreferdSizeBtns ;
- {
- ODHandle pictHandle =
- (itemHit == kDocHeapDefaultSizeTopBtnRect ||
- itemHit == kDocHeapPreferdSizeTopBtnRect) ?
- gArrowBtnsPictTopOn :
- gArrowBtnsPictBotOn ;
- gSizeDialogClickTime = TickCount();
- SetDialogItemAndUpdate(dlg, gSizeDialogClickAt, pictHandle);
- }
-
- // NOTE: deliberately fall through to next bunch o' case statements
- // to pick the appropriate radio button
- case kDocHeapDefaultSizeRadBtn:
- case kDocHeapPreferdSizeRadBtn:
- case kDocHeapDefaultSizeFld:
- case kDocHeapPreferdSizeFld:
- if (allowEditing) {
- newDefaultSizeChosen =
- (itemHit == kDocHeapDefaultSizeRadBtn ||
- itemHit == kDocHeapDefaultSizeFld ||
- itemHit == kDocHeapDefaultSizeTopBtnRect ||
- itemHit == kDocHeapDefaultSizeBotBtnRect ||
- itemHit == kDocHeapDefaultSizeBtns);
- SetDialogBoolean(dlg, kDocHeapDefaultSizeRadBtn, newDefaultSizeChosen, kODTrue);
- SetDialogBoolean(dlg, kDocHeapPreferdSizeRadBtn, !newDefaultSizeChosen, kODTrue);
- }
- break;
- #ifdef _APPLEGUIDE_READY_
- case kDocHeapAppleGuideButton:
- OpenAppleGuide( ODGetIndShort( kODShellGuideSearchIndices,
- kODShellGuideStringIndexSize ) );
- break;
- #endif
- default:
- break;
- }
- } while ((itemHit != kDocHeapOKBtn) && (itemHit != kDocHeapCancelBtn));
- if ((itemHit == kDocHeapOKBtn) && (allowEditing))
- {
- if (newDefaultSizeChosen != kODFalse)
- {
- if (newDefaultSize != curDefaultSize || !curDefaultSizeChosen)
- DHSetODDefaultHeapSize(file, newDefaultSize);
- DHClearDocumentPreferredHeapSize(file);
- }
- else
- {
- if (newPreferredSize != curPreferredSize || curDefaultSizeChosen)
- DHSetDocumentPreferredHeapSize(file, newPreferredSize);
- }
- }
-
- ODDisposeRoutineDescriptor(docHeapSizeUPP);
- DisposeDialog(dlg);
- }
-
- ODStatic ODULong DHGetPreferredSizeInSIZE(PlatformFile* file, ODSShort resourceID)
- {
- // returns 0 if the resource is not found
- ODULong size = 0;
- ODPtr sizeRes =
- file->ReadResourcePtr(kSIZERsrcType, resourceID, kODNULL);
- if (sizeRes != kODNULL)
- {
- memcpy(&size, ((char*)sizeRes)+2, sizeof(size)); // Should probably use a constant.
- ODDisposePtr(sizeRes);
- }
- return size / 1024;
- }
-
- ODStatic void DHSetPreferredSizeInSIZE(PlatformFile* file, ODSShort resourceID,
- PlatformFile* fromFile, ODSShort fromResID, ODULong numKBytes)
- {
- if (fromFile == kODNULL)
- fromFile = file;
- ODULong sizeOfResource;
- ODPtr sizeRes =
- fromFile->ReadResourcePtr(kSIZERsrcType, fromResID, &sizeOfResource);
-
- if (sizeRes != kODNULL)
- {
- numKBytes *= 1024; // Should probably use a constant.
- memcpy(((char*)sizeRes)+2, &numKBytes, sizeof(numKBytes)); // Should probably use a constant.
-
- file->WriteResourcePtr(kSIZERsrcType, resourceID, sizeRes, sizeOfResource);
- ODDisposePtr(sizeRes);
- }
- }
-
-
- ODStatic ODULong DHGetODDefaultHeapSize()
- {
- Environment* ev = somGetGlobalEnvironment();
- PlatformFile* file = gSession->GetNameSpaceManager(ev)->GetPreferences(ev)->GetPrefsFile();
- ODULong size = DHGetPreferredSizeInSIZE(file, -1); // Should probably use a constant.
- if (size == 0)
- size = kDocStubDefaultSize/k1K;
- return size;
- }
-
- ODStatic void DHSetODDefaultHeapSize(PlatformFile* documentFile, ODULong numKBytes)
- {
- Environment* ev = somGetGlobalEnvironment();
- PlatformFile* file = gSession->GetNameSpaceManager(ev)->GetPreferences(ev)->GetPrefsFile();
- DHSetPreferredSizeInSIZE(file, -1, documentFile, -1, numKBytes); // Should probably use a constant.
- }
-
- ODStatic ODULong DHGetDocumentPreferredHeapSize(PlatformFile* file)
- {
- // returns 0 if there is no preferred size
- return DHGetPreferredSizeInSIZE(file, 0); // Should probably use a constant.
- }
-
- ODStatic void DHClearDocumentPreferredHeapSize(PlatformFile* file)
- {
- file->DeleteResource(kSIZERsrcType, 0); // Should probably use constants.
- file->DeleteResource(kSIZERsrcType, 1);
- }
-
-
- ODStatic void DHSetDocumentPreferredHeapSize(PlatformFile* file, ODULong numKBytes)
- {
- DHSetPreferredSizeInSIZE(file, 0, kODNULL, -1, numKBytes); // Should probably use constants.
- DHSetPreferredSizeInSIZE(file, 1, kODNULL, -1, numKBytes);
- }
-
-
- pascal Boolean
- DocHeapArrowButtonsFilterProc(DialogPtr dialog, EventRecord *event, short *itemHit)
- {
- if (event->what == mouseDown)
- {
- gSizeDialogClickAt = 0;
- }
- else if (event->what == mouseUp)
- {
- SetDialogItemAndUpdate(dialog, kDocHeapDefaultSizeBtns, gArrowBtnsPictOff);
- SetDialogItemAndUpdate(dialog, kDocHeapPreferdSizeBtns, gArrowBtnsPictOff);
- }
- else if (((event->modifiers & btnState) == 0) && (event->what == nullEvent))
- { // button down, if for extend period, change value again
- if (TickCount() - gSizeDialogClickTime > kWaitTicksForMoreAction)
- {
- Point thePt = event->where;
- GlobalToLocal(&thePt);
- short hitItem = FindDialogItem(dialog, thePt) + 1;
- if ((hitItem == kDocHeapDefaultSizeTopBtnRect || hitItem == kDocHeapDefaultSizeBotBtnRect) &&
- (gSizeDialogClickAt == kDocHeapDefaultSizeBtns))
- {
- *itemHit = hitItem;
- return true;
- }
- if ((hitItem == kDocHeapPreferdSizeTopBtnRect || hitItem == kDocHeapPreferdSizeBotBtnRect) &&
- (gSizeDialogClickAt == kDocHeapPreferdSizeBtns))
- {
- *itemHit = hitItem;
- return true;
- }
- }
- return ODDialogFilterProc(dialog,event,itemHit);
- }
- return ODDialogFilterProc(dialog,event,itemHit);
- }
-
- //==============================================================================
- // PickOneIText
- // Choose the more "interesting" IText for use as the basis of setting the
- // dialog's script. Those of zero length are not interesting, as the user has
- // not previously typed anything whose appearance he might want preserved.
- // Similarly, the Roman script is not interesting because non-Roman scripts can
- // display Roman text just fine. So we want non-Roman text with content. In
- // the case of a tie either will do -- except that if both are fully interesting
- // it's better to return null and let the default application font win.
- //==============================================================================
-
- static ODScriptCode GetRealScriptCode( ODIText* itext )
- {
- ODScriptCode script;
- if (itext)
- script = GetITextScriptCode( itext );
- else
- script = smSystemScript;
- if ( script == smSystemScript )
- script = GetScriptManagerVariable(smSysScript);
- return script;
- }
-
- ODStatic ODIText* PickOneIText( ODIText* itext1, ODIText* itext2 )
- {
- ODIText* leadingCandidate;
- ODBoolean text1NotRoman = itext1 && GetRealScriptCode( itext1 ) != smRoman;
- ODBoolean text2NotRoman = itext2 && GetRealScriptCode( itext2 ) != smRoman;
-
- if ( text1NotRoman && (GetITextStringLength(itext1) > 0) )
- leadingCandidate = itext1;
- else if ( text2NotRoman && (GetITextStringLength(itext2) > 0) )
- leadingCandidate = itext2;
- else
- leadingCandidate = kODNULL;
-
- if ( leadingCandidate )
- if ( text1NotRoman && text2NotRoman &&
- (GetRealScriptCode( itext1 ) != GetRealScriptCode( itext2 )) )
- leadingCandidate = kODNULL;
- return leadingCandidate;
- }
-
-